home *** CD-ROM | disk | FTP | other *** search
- Program Star;
-
- {
- A Graphic printing example,
- draws a filled pentagram on the screen and the printer.
- This works with any output device as long as the user set
- up the appropriate driver with the Chooser DA.
-
- Algorithm:
- Move to the starting point.
- Start defining polygon.
- set radians to 0
- Draw a horizontal line Dist long.
- Do 4 times.
- Rotate right 144°
- Draw a line Dist long.
- end polygon definition
- Set up printer port
- Draw polygon again
- Print it.
- Close Printer Port.
- }
-
- USES Memtypes,QuickDraw,OSIntf,ToolIntf, MacPrint;
-
- const
- Dist = 150;
- ScalePat = 35;
-
- var
- theline : integer;
- radians,
- x, y : real;
- StarPoly : PolyHandle;
- Scales : Pattern;
- prRecHdl : THPrint;
- result : boolean;
- thePrPort : TPPrPort;
- prStatus : TPrStatus;
-
- procedure Rotate(var theta : real; r : real);
- { rotates a nuber of radians }
-
- Procedure PolarToRect(theta, length : real; var x, y : real);
- { Polar to rectangulal coordinate converter. }
-
- begin { PolarToRect }
- x := Sin(theta) * length;
- y := Cos(theta) * length
- end; { of PolarToRect }
-
- begin { Rotate }
- theta := theta + 1.2 * Pi;
- PolarToRect(radians,Dist,x,y);
- end; { of Rotate }
-
- begin { Star }
- MoveTo(500,100); { Move to the starting point. }
- radians := 0; { set radians to 0 }
- StarPoly := OpenPoly; { Start polygon definition. }
- Line(-dist, 0); { Draw a horizontal line Dist long. }
- For theline := 1 to 4 do
- begin
- Rotate(radians,Dist); { Rotate 144° }
- Line(Trunc(y), Trunc(-x)); { Draw the line }
- end;
- ClosePoly; { End polygon definition. }
- GetIndPattern(Scales, sysPatListID, ScalePat); { Get the fish scale pattern }
- FillPoly(StarPoly,Scales); { Fill the points of the pentagram }
- readln;
- PrOpen; { Open the printer driver }
- prRecHdl := THPrint(NewHandle(SizeOf(TPrint))); { Allocate space for print style record }
- PrintDefault(prRecHdl); { Set style to defaults for the driver }
- result := PrStlDialog(prRecHdl); { This is usually the response to "Page Setup..." }
- if PrJobDialog(prRecHdl) then { And this is the response to "Print." }
- begin
- thePrPort := PrOpenDoc(prRecHdl, NIL, NIL); { Once for each print job }
- if PrError = NoErr then
- begin
- PrOpenPage(thePrPort, NIL); { Call once for each page. }
- if PrError = NoErr then
- FillPoly(StarPoly,Scales); { Draw into the printing grafPort }
- PrClosePage(thePrPort) { Finished with the page }
- end;
- PrCloseDoc(thePrPort); { Finished with the job }
-
- { The next line handles the spooling from the disk if the user chose anything but draft printing.
- If this were a big program I would 'UnloadSeg' everything but the blank segment and the printing
- segment before calling this. }
- if (prRecHdl^^.prJob.BJDocLoop = bSpoolLoop) and (PrError = NoErr) then
- PrPicFile(prRecHdl,NIL,NIL,NIL,prStatus);
- if PrError <> NoErr then
- write(' Printer error code ', PrError)
- end;
- PrClose { We're finished with the printer driver. }
- end. { of Star }